var dbname = 'xxx'
function getList() {
    var list = wx.getStorageSync(dbname)
    if (!list) {
        list = []
    }
    return list;
}
function add(item) {
    var list = getList()
    list.push(item)
    return wx.setStorageSync(dbname, list);
}
function deleteItem(index) {
    var list = getList()
    var newList = []
    for (var i in list) {
        if (i != index) {
            newList.push(list[i])
        }
    }
    wx.setStorageSync(dbname, newList);
}
function newItem() {
    return {
        id: '',
        bank_id: '',
        bank_name: '',
        company_name: '',
        company_telephone: '',
        company_address: '',
        qrcode: ''
    };
}
function getLabel(i){
    var name = "";

    if (i !== '') {
        switch (i) {
            case 'id':
                name = '纳税人号';
                break;
            case 'bank_id':
                name = '银行卡账号';
                break;
            case 'bank_name':
                name = '开户银行';
                break;
            case 'company_name':
                name = '公司名称';
                break;
            case 'company_telephone':
                name = '公司电话';
                break;
            case 'company_address':
                name = '公司地址';
                break;

        }
    }
    return name;
}
function getId(){
    var list = getList();
    return list.length - 1;
}
function toText(item) {
    var text = "";

    text +=   item['company_name'] + '\t';
    text +=   item['id'] + "\t";


    text +=   item['company_address'] + "\t";
    text +=   item['company_telephone'] + "\t";

    text +=   item['bank_name'] + "\t";
    text +=   item['bank_id'] + "\t";
    return text;
}
module.exports = {
    getList: getList,
    add: add,
    deleteItem: deleteItem,
    toText: toText,
    getId:getId,
    newItem: newItem
}